/**
 * 
 */
package org.compiere.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

/**
 * @author A.Yerzhanov
 * 25.11.2012
 */
public class Mhrmtaxexemptionsemployee extends X_hrm_taxexemptionsemployee {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7262800734588252984L;

	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (Mhrmtaxexemptionsemployee.class);
	
	/**
	 * @param ctx
	 */
	public Mhrmtaxexemptionsemployee(Properties ctx) {
		super(ctx);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @param ctx
	 * @param hrm_taxexemptionsemployee_ID
	 * @param trxName
	 */
	public Mhrmtaxexemptionsemployee(Properties ctx,
			int hrm_taxexemptionsemployee_ID, String trxName) {
		super(ctx, hrm_taxexemptionsemployee_ID, trxName);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @param ctx
	 * @param rs
	 * @param trxName
	 */
	public Mhrmtaxexemptionsemployee(Properties ctx, ResultSet rs,
			String trxName) {
		super(ctx, rs, trxName);
		// TODO Auto-generated constructor stub
	}

	public static Mhrmtaxexemptionsemployee[] getExRec(int C_BPartner_ID, Timestamp dt) {
		
		if (C_BPartner_ID == 0)
			return null;
		//
	    PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		ArrayList<Mhrmtaxexemptionsemployee> list = new ArrayList<Mhrmtaxexemptionsemployee>();
		// 
		String sql_ = "SELECT * FROM HRM_TAXEXEMPTIONSEMPLOYEE \n " +
						" WHERE ISACTIVE='Y' \n "  +
							" AND AD_CLIENT_ID="  + Env.getAD_Client_ID(Env.getCtx()) + " \n " +
							" AND C_BPARTNER_ID=" + C_BPartner_ID                     + " \n " +
							" AND " + DB.TO_DATE(dt) + " BETWEEN STARTDATE AND ENDDATE" ;
			try
			{
				pstmt = DB.prepareStatement(sql_,null);
				rs = pstmt.executeQuery();	
				while(rs.next()){
					list.add(new Mhrmtaxexemptionsemployee(Env.getCtx(), rs, null));					
				}
			}
			catch (SQLException e)
			{
				s_log.log(Level.SEVERE, "product", e);
			}
			finally
			{
				DB.close(rs, pstmt);
				rs = null; pstmt = null;
			}	
			
		return list.toArray(new Mhrmtaxexemptionsemployee[list.size()]);		
	}	

}
